#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
template <typename T> inline void rd(T &x){
	x=0;int f=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+c-'0';
	x*=f;
}
int T;
int n,m,L,V;
int d[100010],v[100010],a[100010];
int l[100010],r[100010];
int l1[100010],r1[100010];
int p[100010];
int find1(int i){
	int le=1,ri=m,mid;
	while(le<ri){
		mid=((le+ri)>>1)+1;
		if(p[mid]<l[i])le=mid;
		else ri=mid-1;
	}
	return le;
}
int find2(int i){
	int le=1,ri=m,mid;
	while(le<ri){
		mid=((le+ri)>>1)+1;
		if(p[mid]<r[i])le=mid;
		else ri=mid-1;
	}
	return le;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	rd(T);
	while(T--){
		rd(n);rd(m);rd(L);rd(V);
		for(re int i=1;i<=n;i++){
			rd(d[i]);rd(v[i]);rd(a[i]);
			if(v[i]<=V&&a[i]<=0){
				l[i]=r[i]=0;
				continue;
			}
			double t;
			if(v[i]<=V){
				t=(V*V-v[i]*v[i])*1.0/(2*a[i])+d[i];
				if((int)t!=t)t=t+1,t=(int)t;
				else t=(int)t-1;
				if(t>L){
					l[i]=r[i]=0;
					continue;
				}
				else{
					l[i]=t;
					r[i]=L;
					continue;
				}
			}
			if(v[i]>V){
				if(a[i]>=0){
					l[i]=d[i];
					r[i]=L;
					continue;
				}
				else{
					t=(V*V-v[i]*v[i])*1.0/(2*a[i])+d[i];
					l[i]=d[i];
					r[i]=min(L,(int)t);
					continue;
				}
			}
		}
//		for(re int i=1;i<=n;i++){
//			cout<<l[i]<<" "<<r[i]<<endl;
//		}
		for(re int i=1;i<=m;i++)rd(p[i]);
		int ans=0,k,tot=0;
		for(re int i=1;i<=n;i++){
			k=find1(i)+1;
			if(p[k]>=l[i]&&p[k]<=r[i]){
				l1[++tot]=k;
				r1[tot]=find2(i);
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
